package com.ruyuan.commodity.controller.buyer;

import com.ruyuan.commodity.model.goodssearch.GoodsSearchDTO;
import com.ruyuan.commodity.model.goodssearch.GoodsSearchLine;
import com.ruyuan.commodity.model.goodssearch.GoodsWords;
import com.ruyuan.commodity.open.api.model.common.WebPage;
import com.ruyuan.commodity.common.mamager.GoodsSearchManager;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import java.util.Map;

/**
 * 商品检索相关API
 */
@RestController
@RequestMapping("/goods/search")
public class GoodsSearchBuyerController {

    @Autowired
    private GoodsSearchManager goodsSearchManager;

    @ApiOperation(value = "搜索商品")
    @GetMapping
    public WebPage<GoodsSearchLine> searchGoods(GoodsSearchDTO goodsSearch){
        return goodsSearchManager.search(goodsSearch);
    }

    @ApiOperation(value = "查询商品选择器")
    @GetMapping("/selector")
    public Map<String, Object> searchGoodsSelector(GoodsSearchDTO goodsSearch) {
        return goodsSearchManager.getSelector(goodsSearch);
    }

    @ApiOperation(value = "查询搜索分词对应的商品数量")
    @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true, dataType = "string", paramType = "query")
    @GetMapping("/words")
    public List<GoodsWords> searchGoodsWords(String keyword) {
        return goodsSearchManager.getGoodsWords(keyword);
    }

    @ApiOperation(value = "获取'为你推荐'的商品列表")
    @GetMapping("/recommend")
    public WebPage<GoodsSearchLine> recommendGoodsList(@ApiIgnore Long pageNo, @ApiIgnore Long pageSize) {
        GoodsSearchDTO goodsSearch = new GoodsSearchDTO();
        goodsSearch.setPageNo(pageNo);
        goodsSearch.setPageSize(pageSize);
        return goodsSearchManager.recommendGoodsList(goodsSearch);
    }
}
